package adavance.thread;
import java.util.*;
/**
 * @author oldliu
 * @since 1.0
 */
public class ArrayListDemo {
    public static void main(String[] args) {
        Vector v=new Vector();
        v.add("sss");
        List<String> ar=new ArrayList<>();//new Vector<>();//
        ListThread th=new ListThread(ar);
        for(int i=1;i<=5;i++){
            new Thread(th,"线程"+i).start();
        }
    }
}
class ListThread implements Runnable{
    private final List<String> list;

    public ListThread(List<String> list){
        this.list=list;
    }
    @Override
    public void run() {
        for(int i=1;i<=1000;i++){
           synchronized (list){
                list.add("狗"+i);
            }
        }
        System.out.println(Thread.currentThread().getName()+"这个线程中，集合大小是："+list.size());
    }
}
